package DataStructureAndAlgorithm.BaseAlgorithm.Sort.MergeSort;
import java.util.Scanner;
//归并排序 + 逆序对统计
//时间复杂度O(nlogn)
public class AcWing_788 {
    static int N = 100010;
    static int[] temp = new int[N];
    public static void main(String[] args){
        Scanner in = new Scanner (System.in);
        int n = in.nextInt();
        int[] nums = new int[n + 1];
        for (int i = 0; i < n; i++){
            nums[i] = in.nextInt();
        }
        long res = merge_sort(nums,0,n - 1);
        System.out.print(res);
    }

    static long merge_sort(int[] nums,int left,int right){
        if (left == right)return 0;

        int mid = left + right >> 1;
        long res = merge_sort(nums,left,mid) + merge_sort(nums,mid + 1,right);

        //归并过程

        int k = 0, i = left, j = mid + 1;
        while (i <= mid && j <= right){
            if (nums[i] <= nums[j]){
                temp[k++] = nums[i++];
            }else {
                temp[k++] = nums[j++];
                res += mid - i + 1;
            }
        }
        //扫尾
        while (i <= mid)temp[k++] = nums[i++];
        while (j <= right)temp[k++] = nums[j++];

        //物归原主
        for (int n = left, m = 0; n <= right; n++,m++){
            nums[n] = temp[m];
        }
        return res;
    }
}
